import React from 'react';
import {inject, observer} from 'mobx-react';
import {Modal, Table, Tooltip} from 'antd';
import * as Util from '../../../util/Util';
import NewLinkeb from '../../../public/newlinked/NewLinkeb';
import {WeaInput, WeaInputNumber, WeaLocaleProvider, WeaTextarea, WeaUpload} from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
const toJS = mobx.toJS;

/**
 * 绩效评分table
 */
@inject("accessViewStore")
@observer
export default class AccessViewTable extends React.Component {

  constructor(props) {
    super(props);
  }

  render() {
    const {accessViewStore, tabkey, showtype} = this.props;
    let {datalist, tablewidth, tableHeader, itemcount} = accessViewStore;
    let columns = [];
    if (showtype) {
      //获取datalist属于当前用户的考核指标
      const find = tableHeader.find(item => item.index == tabkey);
      //当前用户特有的考核指标
      let dataLength = datalist.length;
      const arr = datalist.filter((item, index) => index < itemcount && item.userid == find.userid)
      if (arr && arr.length == 0) {
        datalist = datalist.filter((item, index) => ((index < itemcount && item.userid == "") || index >= itemcount) && item.onlyid != 100)
      } else {
        datalist = datalist.filter((item, index) => ((index < itemcount && item.userid == find.userid) || index >= itemcount) && item.onlyid != 100);
      }
      columns = this.getColumns(itemcount - (dataLength - datalist.length) + 1);
    } else {
      const find = tableHeader.find(item => item.index == tabkey);
      let dataLength = datalist.length;
      const arr = datalist.filter((item, index) => index < itemcount && item.userid == find.userid)
      if (arr && arr.length == 0) {
        datalist = datalist.filter((item, index) => ((index < itemcount && item.userid == "") || index >= itemcount))
      } else {
        datalist = datalist.filter((item, index) => ((index < itemcount && item.userid == find.userid) || index >= itemcount));
      }
      columns = this.getOldColumns(itemcount - (dataLength - datalist.length) );
    }

    return (
        <div className="wea-workrelate-perfor-accessviewtable">
          <Table ecId={`${this && this.props && this.props.ecId || ''}_Table@59hc4q`}
              columns={columns}
              bordered={true}
              scroll={{x: showtype ? (1 * 100 + '%') : (tablewidth * 100 + "%")}}
              dataSource={datalist}
              pagination={false}
              className="wea-workrelate-antd-table"/>
        </div>
    )
  }

  getOldColumns(itemnum) {//得到列头
    const {
      accessViewStore: {
        tableHeader, tablewidth, leftwidth, titlestr, canedit, canupload, remark,
        revisemax, revisemin, category, maxUploadSize, scoremin, scoremax, rowcount, hascate
      }
    } = this.props;
    let rightwidth = parseFloat(tablewidth) - parseFloat(leftwidth);
    let columns = [];
    let c_width = 0;
    if (hascate) {
      columns.push({
        title: getLabel('455', '分类'), dataIndex: 'cate', width: leftwidth * 11 + '%',
        render: (text, record, index) => {
          if (index < itemnum) {
            return text;
          }
          if (index == itemnum) {
            return {
              children: <div className="accessview-remark">{getLabel('16965', '相关说明')}<br/><span
                  className="accessview-remark-span" dangerouslySetInnerHTML={{__html: remark}}></span>
              </div>,
              props: {
                colSpan: 5,
                rowSpan: rowcount,
              },
            };
          } else {
            return this.renderContent(text, record, index, itemnum);
          }
        }
      }, {
        title: getLabel('18085', '指标类型'), dataIndex: 'accessitemid', width: leftwidth * 20 + '%',
        render: (text, record, index) => {
          if (index < itemnum) {
            return <span dangerouslySetInnerHTML={{__html: text}}></span>;
          } else {
            return this.renderContent(text, record, index, itemnum);
          }
        }
      });
    } else {
      columns.push({
        title: getLabel('18085', '指标类型'), dataIndex: 'accessitemid', width: leftwidth * 25 + '%',
        render: (text, record, index) => {
          if (index < itemnum) {
            return <span dangerouslySetInnerHTML={{__html: text}}></span>;
          } else if (index == itemnum) {
            return {
              children: <div className="accessview-remark">{getLabel('16965', '相关说明')}<br/>
                <span className="accessview-remark-span" dangerouslySetInnerHTML={{__html: remark}}/>
              </div>,
              props: {
                colSpan: 4,
                rowSpan: rowcount,
              },
            };
          } else {
            return this.renderContent(text, record, index, itemnum);
          }
        }
      });
      c_width = 6;
    }
    columns.push(
        {
          title: getLabel('508669', '指标描述'), dataIndex: 'description', width: leftwidth * (27 + c_width) + '%',
          render: (text, record, index) => {
            if (index < itemnum) {
              return <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@a0lsgo@${record.deatilid}`} title={<span dangerouslySetInnerHTML={{__html: text}}></span>}>
                <span dangerouslySetInnerHTML={{__html: text}}></span></Tooltip>;
            } else {
              return this.renderContent(text, record, index, itemnum);
            }
          }
        },
        {
          title: getLabel('6071', '权重') + '(%)', dataIndex: 'rate', width: leftwidth * 9 + '%',
          render: (text, record, index) => this.renderContent(text, record, index, itemnum)
        },
        {
          title: getLabel('18087', '目标值'), dataIndex: 'itemtarget', width: leftwidth * 11 + '%',
          render: (text, record, index) => {
            if (canedit && !(record.itemtype == 2 && (record.formula == 2 || record.formula == 3))) {
              if (record.itemtype == 2) {  //formula!=0的时候才能触发change事件
                if (record.formula == 13) {
                  text = <span className="accessview-input-lineh">
                                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@0cgz7a@${record.deatilid}`}
                                        viewAttr='3'
                                        className="accessview-input-width"
                                        value={text}
                                        onBlur={(v) => this.doChange(v, record.dataNum, "itemtarget", 3)}/>
                                    <div className="accessview-unit-div">{record.unit}</div>
                                </span>
                } else {
                  text = <span>
                                    <div className="accessview-input-width">
                                        <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@b8b7au@${record.deatilid}`}
                                            viewAttr='3'
                                            value={text}
                                            precision={2}
                                            onChange={(v) => this.doChange(v, record.dataNum, "itemtarget", 1)}/></div>
                                    <div className={text != "" ? "accessview-unit-div" : ""}>
                                        {record.unit}
                                    </div>
                                </span>
                }
              } else {
                text = <span className="accessview-input-lineh">
                                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@wvfron@${record.deatilid}`}
                                    className="accessview-input-width"
                                    value={text}
                                    onBlur={(v) => this.doChange(v, record.dataNum, "itemtarget")}/>
                  {record.unit}
                            </span>
              }
            } else {
              text = <span>{text + record.unit}</span>;
            }
            return this.renderContent(text, record, index, itemnum)
          }
        },
        {
          title: getLabel('508618', '完成值'), dataIndex: 'itemresult', width: leftwidth * 11 + '%',
          render: (text, record, index) => {
            if (index < itemnum) {
              if (record.itemtype == 2 && (record.formula == 2 || record.formula == 3)) {
                text = <span>{"实际：" + text + record.unit + "有效：" + record.validresult + record.unit}</span>
              } else if (canedit) {
                if (record.itemtype == 2) {  //formula!=0的时候才能触发change事件
                  if (record.formula == 13) {
                    text = <span className="accessview-input-lineh">
                                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@k0zxhq@${record.deatilid}`}
                                            className="accessview-input-width"
                                            viewAttr='3'
                                            value={text}
                                            onBlur={(v) => this.doChange(v, record.dataNum, "itemresult", 3)}/>
                      {record.unit}
                                    </span>
                  } else {
                    text = <span><div className="accessview-input-width">
                                        <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@a0fkq5@${record.deatilid}`}
                                            value={text}
                                            precision={2}
                                            viewAttr='3'
                                            onChange={(v) => this.doChange(v, record.dataNum, "itemresult", 1)}/></div>
                                        <div className={text != "" ? "accessview-unit-div" : ""}>{record.unit}</div>
                                    </span>
                  }
                } else {
                  text = <span className="accessview-input-lineh">
                                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@ad0p5u@${record.deatilid}`}
                                        value={text}
                                        className="accessview-input-width"
                                        onBlur={(v) => this.doChange(v, record.dataNum, "itemresult")}/>
                    {record.unit}
                                </span>
                }
              } else {
                text = <span>{text + record.unit}</span>;
              }
              return text;
            }
            return {
              children: text,
              props: {
                colSpan: 2,
              },
            };
          }
        },
        {
          title: titlestr + getLabel('330', '目标'), dataIndex: 'itemnext', width: leftwidth * 11 + '%',
          render: (text, record, index) => {
            if (canedit) {
              if (record.itemtype == 2) {
                text = <span><div className="accessview-input-width">
                                <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@fd5fqy@${record.deatilid}`}
                                    value={text}
                                    viewAttr='3'
                                    precision={2}
                                    onChange={(v) => this.doChange(v, record.dataNum, "itemnext", 2)}/></div>
                                <div
                                    className={text != "" ? "accessview-unit-div" : ""}>{record.unit}</div>
                            </span>
              } else {
                text = <span className="accessview-input-lineh">
                                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@xnvs7c@${record.deatilid}`}
                                    className="accessview-input-width"
                                    value={text}
                                    onBlur={(v) => this.doChange(v, record.dataNum, "itemnext")}/>
                  {record.unit}
                            </span>
              }
            } else {
              text = <span>{text + record.unit}</span>;
            }
            return this.renderContent(text, record, index, itemnum);
          }
        }
    );
    if (tableHeader && tableHeader.length > 1) {
      rightwidth = 0.2;
    }
    tableHeader && tableHeader.length > 0 && tableHeader.map((element, idx) => {
      let column = {
        title: <span dangerouslySetInnerHTML={{__html: element.name}}></span>,
        children: [{
          title: getLabel('25622', '评分'), dataIndex: 'score_' + element.index, width: rightwidth * 30 + "%",
          render: (text, record, index) => {
            if (index < itemnum) {
              if (record["edit_" + element.index] == 1 && (record.itemtype == 1 || (record.itemtype == 2 && (record.formula == 0 || record.formula == 4)))) {
                text =
                    <span className="accessview-score-must">
                                        <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@9br4u1@${record.deatilid}_${element.userid}_${index}`}
                                            value={text}
                                            precision={2}
                                            min={scoremin}
                                            max={scoremax} viewAttr='3'
                                            onChange={(v) => this.doScoreChange(v, record.dataNum, element.index)}/>
                                    </span>;
              }
              return this.renderContent(text, record, index, itemnum);
            } else {
              if (record.onlyid == 100) {
                if (idx == 0) {
                  return {
                    children: <span className="accessview-result-score">{text}</span>,
                    props: {colSpan: tableHeader.length * 3}
                  };
                } else {
                  return this.renderContent(text, record, index, itemnum);
                }
              }
              if (record.onlyid == 2) {//修正分处理
                let revise = "";
                if (record["isedit" + element.index] == 1 && !(revisemax == 0 && revisemin == 0)) {
                  revise =
                      <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@7599nx@${record["checkid"+element.index]}_${element.userid}`}
                          className="accessview-revise-score"
                          value={text}
                          precision={2}
                          min={revisemin}
                          max={revisemax}
                          onChange={(v) => this.onResiveChange(v, record.dataNum, element.index)}/>;
                } else {
                  revise = text;
                }
                if (text != 0) {
                  if (record["isedit" + element.index] == 1) {
                    revise = <span>{revise}
                      <div className="accessview-revise-reason">
                                                <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@drv0ar@${record["checkid"+element.index]}_${element.userid}`}
                                                    value={record['reason' + element.index]}
                                                    viewAttr='3'
                                                    placeholder={getLabel(509457, "请输入修正分理由")}
                                                    onChange={(v) => this.doChange(v, record.dataNum, 'reason' + element.index)}/></div>
                                        </span>;
                  } else {
                    revise = <span>{revise}<br/><span
                        dangerouslySetInnerHTML={{__html: record['reason' + element.index]}}></span></span>;
                  }
                }
                text = revise;
              }
              if (record.onlyid == 3) {//考核评价
                if (record["isedit" + element.index] == 1) {
                  text = <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@7w4eax@${record["checkid"+element.index]}_${element.userid}`}
                      value={text}
                      onChange={(v) => this.doChange(v, record.dataNum, 'score_' + element.index)}/>
                } else {
                  text = <span dangerouslySetInnerHTML={{__html: text}}></span>;
                }
              }
              if (record.onlyid == 4) {//相关附件
                if (record["isedit" + element.index] == 1 && canupload) {
                  text = <span>
                                        <WeaUpload ecId={`${this && this.props && this.props.ecId || ''}_WeaUpload@8n89o1@${record["checkid"+element.index]}_${element.userid}`}
                                            ref={(el) => this.setRef(el)}
                                            uploadUrl={'/api/doc/upload/uploadFile2Doc?category=' + category}
                                            category={category}
                                            maxUploadSize={maxUploadSize}
                                            showClearAll={false}
                                            autoUpload={false}
                                            getShowListDatas={(listT, listB) => this.setUploading(listB)}
                                            onChange={(ids, datas) => this.uploadChange(ids, datas)}/>
                                      <NewLinkeb ecId={`${this && this.props && this.props.ecId || ''}_NewLinkeb@lxzsxw@${record["checkid"+element.index]}_${element.userid}`}
                                          _width='20'
                                          onLinkClick={(id, name, type, fileid) => this.onLinkClick(id, name, type, index, element.index, fileid)}
                                          linkdatas={text}
                                          hasdel={true}
                                          hasdownload={true}/>
                                      </span>;
                } else {
                  text = <NewLinkeb ecId={`${this && this.props && this.props.ecId || ''}_NewLinkeb@pqfzw9@${record["checkid"+element.index]}_${element.userid}`}
                      _width='20'
                      onLinkClick={(id, name, type, fileid) => this.onLinkClick(id, name, type, index, '', fileid)}
                      linkdatas={text}
                      hasdel={false}
                      hasdownload={true}/>;
                }
              }
              return {children: text, props: {colSpan: 3}};
            }
          }
        },
          {
            title: getLabel('17506', '得分'),
            dataIndex: 'result_' + element.index,
            width: rightwidth * 20 + "%",
            render: (text, record, index) => this.renderContent(text, record, index, itemnum)
          },
          {
            title: getLabel('25734', '说明'),
            dataIndex: 'remark_' + element.index,
            width: rightwidth * 50 + "%",
            render: (text, record, index) => {
              if (record["edit_" + element.index] == 1) {
                text = <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@zr0vif@${record.deatilid}_${element.userid}_${index}`}
                    value={text}
                    onChange={(v) => this.doChange(v, record.dataNum, 'remark_' + element.index)}/>;
              } else {
                text = <span dangerouslySetInnerHTML={{__html: text}}></span>;
              }
              return this.renderContent(text, record, index, itemnum);
            }
          }
        ]
      };
      columns.push(column);
    });
    return columns;
  }

  /**
   * 构建内容
   * @param value 显示值
   * @param row
   * @param index
   * @param idx
   */
  renderContent = (value, row, index, idx) => {
    const obj = {
      children: value,
      props: {},
    };
    if (index >= idx) {
      obj.props.colSpan = 0;
      obj.props.rowSpan = 0;
    }
    return obj;
  };

  /**
   * 修正分改变
   * @param val 最新值
   * @param index datalist索引
   * @param idx 评分人索引
   */
  onResiveChange(val, dataNum, idx) {
    const {accessViewStore} = this.props;
    const {canedit, datalist, revisemax, revisemin} = accessViewStore;
    if (isNaN(val)) {
      val = 0;
    }
    let index = datalist.findIndex(item => item.dataNum == dataNum);
    if (canedit && val != undefined && datalist[index]["score_" + idx] != val) {
      if (val < revisemin || val > revisemax) {
        Modal.warning({
          title: getLabel('558', '提示'),
          content: getLabel('509182', '修正分值需控制在{revisemin}-{revisemax}之间').replace('{revisemin}', revisemin).replace('{revisemax}', revisemax),
        });
        return;
      }
      accessViewStore.canedit = false;
      accessViewStore.datalist[index]["score_" + idx] = val;
      accessViewStore.countscore(idx);
      accessViewStore.canedit = true;
    }
  }

  /**
   * 定性指标直接评分
   * @param val 最新值
   * @param index datalist索引
   * @param idx 评分人索引
   */
  doScoreChange(val, dataNum, idx) {
    const {accessViewStore} = this.props;
    const {canedit, datalist, scoremax, scoremin} = accessViewStore;
    if (isNaN(val)) {
      val = 0;
    }
    let index = datalist.findIndex(item => item.dataNum == dataNum);
    if (canedit && val != undefined && datalist[index]["score_" + idx] != val) {
      if (val < scoremin || val > scoremax) {
        Modal.warning({
          title: getLabel('558', '提示'),
          content: getLabel('509183', '评分值需控制在{scoremin}-{scoremax}之间').replace('{scoremin}', scoremin).replace('{scoremax}', scoremax),
        });
        return;
      }
      accessViewStore.canedit = false;
      accessViewStore.datalist[index]["score_" + idx] = val;
      accessViewStore.updateScore(index, idx);
      accessViewStore.canedit = true;
    }
  }

  /**
   * 更改值
   * @param val 最新值
   * @param index 前索引
   * @param type 改变的值type
   * @param resetcount 是否重新计算评分 1-是
   */
  doChange(val, dataNum, type, resetcount) {
    const {accessViewStore} = this.props;
    const {canedit, datalist} = accessViewStore;
    if (resetcount && resetcount > 0) {
      if (isNaN(val)) {
        val = 0;
      }
    }
    let index = datalist.findIndex(item => item.dataNum == dataNum);
    if (canedit && val != undefined && datalist[index][type] != val) {
      if (resetcount != 3) {
        accessViewStore.canedit = false;
      }
      accessViewStore.datalist[index][type] = val;
      if (resetcount == 1 || resetcount == 3) {
        accessViewStore.updateNormScore(index);
      } else {
        accessViewStore.canedit = true;
      }
    } else if (canedit && resetcount == 3) {
      accessViewStore.canedit = false;
      accessViewStore.datalist[index][type] = val;
      accessViewStore.canedit = true;
    }
  }

  /**
   * 得到列头
   * @param itemNum 当前tab页用户的考核指标数量
   */
  getColumns(itemNum) {
    const {accessViewStore: {tableHeader, titlestr, canupload, remark, revisemax, revisemin, category, maxUploadSize, scoremin, scoremax, hascate}} = this.props;
    let {accessViewStore: {rowcount, canedit}, showtype} = this.props;
    const {tabkey} = this.props;

    rowcount=rowcount-1;
    //若编辑状态下，当前tab不属于当前用户
    if (canedit && !tableHeader.find(item => item.edit == 1 && item.index == tabkey)) {
      canedit = false
    }

    let columns = [];
    let c_width = 0;
    if (hascate) {
      columns.push({
        title: getLabel('455', '分类'), dataIndex: 'cate', width: 0.75 * 11 + '%',
        render: (text, record, index) => {
          if (index < itemNum) {
            return text;
          }
          if (index == itemNum) {
            return {
              children: <div className="accessview-remark">{getLabel('16965', '相关说明')}
                <br/>
                <span className="accessview-remark-span" dangerouslySetInnerHTML={{__html: remark}}/>
              </div>,
              props: {colSpan: 5, rowSpan: rowcount}
            };
          } else {
            return this.renderContent(text, record, index, itemNum);
          }
        }
      }, {
        title: getLabel('18085', '指标类型'), dataIndex: 'accessitemid', width: 0.75 * 20 + '%',
        render: (text, record, index) => {
          if (index < itemNum) {
            return <span dangerouslySetInnerHTML={{__html: text}}></span>;
          } else {
            return this.renderContent(text, record, index, itemNum);
          }
        }
      });
    } else {
      columns.push({
        title: getLabel('18085', '指标类型'), dataIndex: 'accessitemid', width: 0.75 * 25 + '%',
        render: (text, record, index) => {
          if (index < itemNum) {
            return <span dangerouslySetInnerHTML={{__html: text}}></span>;
          } else if (index == itemNum) {
            return {
              children: <div className="accessview-remark">{getLabel('16965', '相关说明')}
                <br/>
                <span className="accessview-remark-span" dangerouslySetInnerHTML={{__html: remark}}/>
              </div>,
              props: {colSpan: 4, rowSpan: rowcount}
            };
          } else {
            return this.renderContent(text, record, index, itemNum);
          }
        }
      });
      c_width = 6;
    }
    columns.push(
        {
          title: getLabel('508669', '指标描述'), dataIndex: 'description', width: 0.75 * (27 + c_width) + '%',
          render: (text, record, index) => {
            if (index < itemNum) {
              return <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@6zxxw0@${record.deatilid}`} title={<span dangerouslySetInnerHTML={{__html: text}}/>}>
                <span dangerouslySetInnerHTML={{__html: text}}/>
              </Tooltip>;
            } else {
              return this.renderContent(text, record, index, itemNum);
            }
          }
        },
        {
          title: getLabel('6071', '权重') + '(%)', dataIndex: 'rate', width: '6.75%',
          render: (text, record, index) => this.renderContent(text, record, index, itemNum)
        },
        {
          title: getLabel('18087', '目标值'), dataIndex: 'itemtarget', width: '8.25%',
          render: (text, record, index) => {
            if (canedit && !(record.itemtype == 2 && (record.formula == 2 || record.formula == 3))) {
              if (record.itemtype == 2) {  //formula!=0的时候才能触发change事件
                if (record.formula == 13) {
                  text = <span className="accessview-input-lineh">
                                  <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@8lwezh@${record.deatilid}`}
                                      viewAttr='3'
                                      className="accessview-input-width"
                                      value={text}
                                      onBlur={(v) => this.doChange(v, record.dataNum, "itemtarget", 3)}/>
                                <div className="accessview-unit-div">{record.unit}</div>
                                </span>
                } else {
                  text = <span><div className="accessview-input-width">
                                  <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@ttmp40@${record.deatilid}`}
                                      viewAttr='3'
                                      value={text}
                                      precision={2}
                                      onChange={(v) => this.doChange(v, record.dataNum, "itemtarget", 1)}/></div>
                                  <div className={text != "" ? "accessview-unit-div" : ""}>{record.unit}</div>
                                </span>
                }
              } else {
                text = <span className="accessview-input-lineh">
                              <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@a9gy1w@${record.deatilid}`}
                                  className="accessview-input-width"
                                  value={text}
                                  onBlur={(v) => this.doChange(v, record.dataNum, "itemtarget")}/>
                  {record.unit}
                            </span>
              }
            } else {
              text = <span>{text + record.unit}</span>;
            }
            return this.renderContent(text, record, index, itemNum)
          }
        },
        {
          title: getLabel('508618', '完成值'), dataIndex: 'itemresult', width: '8.25%',
          render: (text, record, index) => {
            if (index < itemNum) {
              if (record.itemtype == 2 && (record.formula == 2 || record.formula == 3)) {
                text = <span>{"实际：" + text + record.unit + "有效：" + record.validresult + record.unit}</span>
              } else if (canedit) {
                if (record.itemtype == 2) {  //formula!=0的时候才能触发change事件
                  if (record.formula == 13) {
                    text = <span className="accessview-input-lineh">
                                      <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@2249gm@${record.deatilid}`}
                                          className="accessview-input-width"
                                          viewAttr='3'
                                          value={text}
                                          onBlur={(v) => this.doChange(v, record.dataNum, "itemresult", 3)}/>
                      {record.unit}
                                    </span>
                  } else {
                    text = <span><div className="accessview-input-width">
                                      <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@n5528x@${record.deatilid}`}
                                          value={text}
                                          precision={2}
                                          viewAttr='3'
                                          onChange={(v) => this.doChange(v, record.dataNum, "itemresult", 1)}/>
                                    </div>
                                      <div
                                          className={text != "" ? "accessview-unit-div" : ""}>{record.unit}</div></span>
                  }
                } else {
                  text = <span className="accessview-input-lineh">
                                  <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@si4s2k@${record.deatilid}`}
                                      value={text}
                                      className="accessview-input-width"
                                      onBlur={(v) => this.doChange(v, record.dataNum, "itemresult")}/>
                    {record.unit}
                                </span>
                }
              } else {
                text = <span>{text + record.unit}</span>;
              }
              return text;
            }
            return {
              children: text,
              props: {
                colSpan: 2,
              },
            };
          }
        },
        {
          title: titlestr + getLabel('330', '目标'), dataIndex: 'itemnext', width: '8.25%',
          render: (text, record, index) => {
            if (canedit) {
              if (record.itemtype == 2) {
                text = <span><div className="accessview-input-width">
                                <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@fvn4mn@${record.deatilid}`}
                                    value={text}
                                    viewAttr='3'
                                    precision={2}
                                    onChange={(v) => this.doChange(v, record.dataNum, "itemnext", 2)}/>
                              </div>
                              <div className={text != "" ? "accessview-unit-div" : ""}>{record.unit}</div>
                            </span>
              } else {
                text = <span className="accessview-input-lineh">
                              <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@n0mn8b@${record.deatilid}`}
                                  className="accessview-input-width"
                                  value={text}
                                  onBlur={(v) => this.doChange(v, record.dataNum, "itemnext")}/>
                  {record.unit}
                            </span>
              }
            } else {
              text = <span>{text + record.unit}</span>;
            }
            return this.renderContent(text, record, index, itemNum);
          }
        }
    );
    tableHeader && tableHeader.length > 0 && tableHeader.map((element, idx) => {
      if (element.index == tabkey) {
        columns.push({
          title: getLabel('25622', '评分'), dataIndex: 'score_' + element.index, width: "7.5%",
          render: (text, record, index) => {
            if (index < itemNum) {
              if (record["edit_" + element.index] == 1 && (record.itemtype == 1 || (record.itemtype == 2 && (record.formula == 0 || record.formula == 4)))) {
                text = <span className="accessview-score-must">
                                      <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@s5nomg@${record.deatilid}_${element.userid}_${index}`}
                                          value={text}
                                          precision={2}
                                          min={scoremin}
                                          max={scoremax} viewAttr='3'
                                          onChange={(v) => this.doScoreChange(v, record.dataNum, element.index)}/>
                                    </span>;
              }
              return this.renderContent(text, record, index, itemNum);
            } else {
              if (record.onlyid == 2) {//修正分处理
                let revise = "";
                if (record["isedit" + element.index] == 1 && !(revisemax == 0 && revisemin == 0)) {
                  revise = <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@qjechw@${record["checkid"+element.index]}_${element.userid}`}
                      className="accessview-revise-score"
                      value={text} precision={2}
                      min={revisemin} max={revisemax}
                      onChange={(v) => this.onResiveChange(v, record.dataNum, element.index)}/>;
                } else {
                  revise = text;
                }
                if (text != 0) {
                  if (record["isedit" + element.index] == 1) {
                    revise = <span>{revise}
                      <div className="accessview-revise-reason">
                                                <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@pkvc0a@${record["checkid"+element.index]}_${element.userid}`}
                                                    value={record['reason' + element.index]}
                                                    viewAttr='3'
                                                    placeholder={getLabel(509457, "请输入修正分理由")}
                                                    onChange={(v) => this.doChange(v, record.dataNum, 'reason' + element.index)}/>
                                            </div>
                                        </span>;
                  } else {
                    revise = <span>{revise}<br/>
                                            <span dangerouslySetInnerHTML={{__html: record['reason' + element.index]}}/>
                                        </span>;
                  }
                }
                text = revise;
              }
              if (record.onlyid == 3) {//考核评价
                if (record["isedit" + element.index] == 1) {
                  text = <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@8xf8op@${record["checkid"+element.index]}_${element.userid}`}
                      value={text}
                      onChange={(v) => this.doChange(v, record.dataNum, 'score_' + element.index)}/>
                } else {
                  text = <span dangerouslySetInnerHTML={{__html: text}}></span>;
                }
              }
              if (record.onlyid == 4) {//相关附件

                if (record["isedit" + element.index] == 1 && canupload) {
                  text = <span>
                                        <WeaUpload ecId={`${this && this.props && this.props.ecId || ''}_WeaUpload@mllxk4@${record["checkid"+element.index]}_${element.userid}`}
                                            ref={(el) => this.setRef(el)}
                                            uploadUrl={'/api/doc/upload/uploadFile2Doc?category=' + category}
                                            category={category} maxUploadSize={maxUploadSize}
                                            showClearAll={false} autoUpload={false}
                                            getShowListDatas={(listT, listB) => this.setUploading(listB)}
                                            onChange={(ids, datas) => this.uploadChange(ids, datas)}/>
                                       <NewLinkeb ecId={`${this && this.props && this.props.ecId || ''}_NewLinkeb@5qpsi9@${record["checkid"+element.index]}_${element.userid}`}
                                           _width='20'
                                           onLinkClick={(id, name, type, fileid) => this.onLinkClick(id, name, type, index, element.index, fileid)}
                                           linkdatas={text}
                                           hasdel={true}
                                           hasdownload={true}/>
                              </span>;
                } else {
                  text = <NewLinkeb ecId={`${this && this.props && this.props.ecId || ''}_NewLinkeb@iihg0k@${record["checkid"+element.index]}_${element.userid}`}
                      _width='20'
                      onLinkClick={(id, name, type, fileid) => this.onLinkClick(id, name, type, index, '', fileid)}
                      linkdatas={text}
                      hasdel={false}
                      hasdownload={true}/>;
                }
              }
              return {children: text, props: {colSpan: 3}};
            }
          }
        },);
        columns.push({
          title: getLabel('17506', '得分'),
          dataIndex: 'result_' + element.index,
          width: "5%",
          render: (text, record, index) => this.renderContent(text, record, index, itemNum)
        },)
        columns.push({
          title: getLabel('25734', '说明'),
          dataIndex: 'remark_' + element.index,
          width: "12.5%",
          render: (text, record, index) => {
            if (record["edit_" + element.index] == 1) {
              text = <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@1urbg4@${record.deatilid}_${element.userid}_${index}`}
                  value={text}
                  onChange={(v) => this.doChange(v, record.dataNum, 'remark_' + element.index)}/>;
            } else {
              text = <span dangerouslySetInnerHTML={{__html: text}}></span>;
            }
            return this.renderContent(text, record, index, itemNum);
          }
        })
      }

    });
    return columns;
  }

  setRef(el) {
    const {accessViewStore} = this.props;
    accessViewStore.uploadref = el;
  }

  saveUpload() {
    const {accessViewStore} = this.props;
    if (accessViewStore.uploadref) {
      accessViewStore.uploadref.doUpload();
    }
  }

  setUploading(listB) {
    const {accessViewStore} = this.props;
    if (listB.length > 0) {
      accessViewStore.uploading = true;
    } else {
      accessViewStore.uploading = false;
    }
  }

  uploadChange(ids, list) {
    const {accessViewStore} = this.props;
    if (ids.length > 0) {
      accessViewStore.fileids = ids.toString();
    }
    accessViewStore.uploading = false;
    if (typeof this.props.onCallBack === "function") {
      this.props.onCallBack();
    }
  }

  onLinkClick(id, name, type, index, idx, fileid) {
    const {accessViewStore} = this.props;
    if (type == 2) {//删除
      Modal.confirm({
        title: getLabel('386786', '信息确认'),
        content: getLabel('508898', '确认要删除此附件吗？'),
        onOk() {
          const {datalist, delfileids} = accessViewStore;
          accessViewStore.delfileids = delfileids + "," + id;
          let filelist = datalist[index]["score_" + idx];
          let fileids = datalist[index]["fileid_" + idx];
          let cid = -1;
          for (let i = 0; i < filelist.length; i++) {
            let files = filelist[i];
            if (files.id == id) {
              cid = i;
            }
          }
          if (cid != -1) {
            filelist.splice(cid, 1);
          }
          let _index = fileids.indexOf("," + id + ",");
          if (_index > -1 && id != "") {
            fileids = fileids.substring(0, _index + 1) + fileids.substring(_index + (id + "").length + 2);
            if (fileids == ',') {
              fileids = '';
            }
          }
          accessViewStore.canedit = false;
          accessViewStore.datalist[index]["score_" + idx] = filelist;
          accessViewStore.datalist[index]["fileid_" + idx] = fileids;
          accessViewStore.canedit = true;
        },
        onCancel() {
        },
      });
    } else if (type == 3) {//下载
      accessViewStore.viewDocFiled({
        id: id, relateId: accessViewStore.scoreid, type: 3, doback: function () {
          Util.downloads(fileid);
        }
      });
    } else {//查看
      accessViewStore.viewDocFiled({
        id: id, relateId: accessViewStore.scoreid, type: 3, doback: function () {
          Util.opendoc(id);
        }
      });
    }
  }
};